tool
extends EditorScript



func _run():
	var face = get_editor_interface()
	var root = get_editor_interface().get_edited_scene_root()
	var port:Node = get_editor_interface().get_editor_viewport()
	var base:Node = get_editor_interface().get_base_control()
	
#	print(face)
#	print(base)
#	print(port)
	replace_node("LineEdit")
	
#	#新建空场景
#	var add_scene_btn:ToolButton =  root.find_node("@@625",true,false)
#	add_scene_btn.emit_signal("pressed")

func replace_node(nodeType:String):
	var root = get_editor_interface().get_tree().root
	var scene_tree_dock = root.find_node("Scene",true,false)
	scene_tree_dock._tool_selected(8)
	var create_dialog = find_child_as_class(scene_tree_dock,"CreateDialog")
	var txt:LineEdit = create_dialog.find_node("@@2824",true,false) # 搜索框
	var creBtn:Button = create_dialog.find_node("@@2786",true,false) # 创建按钮
	txt.text = nodeType # 修改搜索关键字
	txt.emit_signal("text_changed",nodeType) # 触发“文本改变”信号
	creBtn.emit_signal("pressed") # 触发“创建”按钮pressed信号

#	if not get_editor_interface().get_edited_scene_root():# 当前场景为空场景
#		# 新建根节点
#		var scene_tree_dock = root.find_node("Scene",true,false)
		



# 返回对应类名的子节点
func find_child_as_class(node:Node,className:String):
	var children = node.get_children()
	for child in children:
		if child.is_class(className):
			return child

#	# 新建空场景
#	var tbtn:ToolButton = instance_from_id(4090)
#	tbtn.emit_signal("pressed")
#	# 创建2D根节点
#	var btn:Button = instance_from_id(18021)
#	btn.emit_signal("pressed")
#
#	var root:Button = Button.new()
#	get_editor_interface().get_edited_scene_root().get_parent().add_child(root)
#	get_editor_interface().get_edited_scene_root().replace_by(root)
	
func printChildren(node:Node,deep:=0):
	var children = node.get_children()
	for child in children:
		print("\t".repeat(deep),child.name,":",child,"\n")
		if child.get_child_count()>0 and deep<4:
			printChildren(child,deep+1)

